/**
 * 
 */
app.config(function($stateProvider) {
	$stateProvider.state('recrut2.dmdpri', {
		url: '/dmdpri',
		templateUrl: './views/DemandPriority.html',
		controller: 'DPCtr',
		controller: ['$state', function($state) {
			$state.go('recrut2.dmdpri');
		}]
	}).state('recrut2.dmdpri.option', {
		url: '/option',
		templateUrl: './views/slidePrio.html',
		controller: ['$rootScope','$scope' ,'$http','$uibModal','$state','editReloadService',function($rootScope,$scope,$http,$uibModal,$state,editReloadService) {
			//console.log($rootScope.demandRequest);
			$scope. priorities = ["High","Medium","Low"];
			$scope.demandPriority = angular.copy($rootScope.demandPriority);
			console.log($scope.demandPriority);
			$scope.demandPriority.weekStart = new Date();
			$scope.demandPriority.weekEnd = new Date();
			$scope.demandPriority.weekEnd = $scope.demandPriority.weekEnd.setDate($scope.demandPriority.weekStart.getDate()+7);
			$scope.format = "yyyy/MM/dd";
			$scope.altInputFormats = [ 'yyyy/M!/d!' ];
			
			
			
			   $scope.$watch('demandPriority.weekStart',function(){
				  
        		  
				//   $scope.demandPriority.weekEnd.setDate($scope.demandPriority.weekStart.getTime()+604800);
/*				   var date = $scope.demandPriority.weekEnd.getDate();
				   var month = $scope.demandPriority.weekEnd.getMonth(); 
				   var year = $scope.demandPriority.weekStart.getFullYear();
				   
				   $scope.demandPriority.weekEnd = month+"-"+date+"-"+year;
         		   console.log( $scope.demandPriority.weekEnd);
				   $scope.demandPriority.weekEnd.setDate(year,month,date);
				   */
				
         		   
         	   });

			$scope.popup1 = {
				opened : false
			};
			$scope.popup2 = {
				opened : false
			};
			$scope.open1 = function() {
				
				$scope.popup1.opened = true;			
			};
			$scope.open2 = function() {
				$scope.popup2.opened = true;		
			};			
			$scope.confirm = function(){
				/*$scope.demandPriority.= $scope.demandRequest;*/
				var tobackend = $scope.demandPriority;
				console.log(tobackend);
				
				$http({
					method : 'POST',
					url :'/DRMS/api/DrmsDemandRequestPriority/updateDrmsDemandRequestPriority',
					headers: {
						'Content-Type': 'application/json'
					},
					data :tobackend
				});
				
				var modalInstance = $uibModal.open({
                    animation: false,
                    size: 'sm',
                    templateUrl: './views/coralert.html',
                    controller: 'alertController',
                    resolve: {
                         item: function() {
                               return ' DEMADN REQUEST PRIORITY EDIT  SUCCESS.';
                         }
                    }
               });
               
               modalInstance.result.then(function() {
            	   editReloadService.promiseDeferd.notify('promise noitfy');
            	 /*  $state.go('recrut2.dmdpri',null,{
            		    reload:true
            		});*/
            	          	   
               }, function() {
            	   editReloadService.promiseDeferd.notify('promise noitfy');
                    $state.go('^');
               });
               $state.go('^');
			}	
		}]
	}) 
});